library Wave18a initializer init requires LegacySystem, EndCinematics


    globals
        private trigger EngineerDeployTrigger = null
        private trigger EngineerArriveTrigger = null
        private trigger FinalUndeadSpawnTrigger = null
        
        private trigger EMManualReleaseTrigger = null
        private trigger EMAutoChargeTrigger = null
        
        private trigger FinalBossKillListenerTrigger = null
		
		private integer                 udg_EngineersOnSite        = 0
		private integer                 udg_EMSphere               = 0
		private integer                 udg_EMSphereRelease        = 0
		private integer                 udg_EMSphereAuthorization  = 0
		private unit                    udg_bunny_boss              = null
		private boolean 				EMSphereReleased = false
		
		private boolean                 udg_SectorLockdown         = false
    endglobals


   
   
   
   private function AIBunny takes nothing returns nothing
		local real x
		local real y
		set x = GetUnitX(udg_AITarget)+GetRandomReal(-500.0,500.0)
		set y = GetUnitY(udg_AITarget)+GetRandomReal(-500.0,500.0)
		call IssuePointOrder(udg_bunny_boss,"move",x,y)
	endfunction
	


    /*
    EM Sphere 1.5 -> 5
    EM Sphere 2 5.0 -> 8.0

    ConvoyLoss=1337 : EM Sphere released
    */

    private function EMSphereDamage takes nothing returns nothing
        call SetUnitExploded(GetEnumUnit(),true)
        call UnitDamageTarget(udg_Residence41,GetEnumUnit(),I2R(udg_EMSphere)*1750.0,true,false,ATTACK_TYPE_SIEGE,DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS)
    endfunction

    private function SelectEnemyUnits takes nothing returns boolean
        local integer i = GetUnitPointValue(GetFilterUnit())
        return i==100 or i==50
    endfunction

    private function EMSphereRelease takes nothing returns nothing
        local integer i = 1
        local group g
        local unit u
        call DisableTrigger(EMManualReleaseTrigger)
		
        if EMSphereReleased then
            return
        endif
		
		set EMSphereReleased = true
        set udg_AITarget = null
        call SetImmortalSpawnEnabled(false)
        call SetCrepitusSpawnEnabled(false)
        call SetGhoulSpawnEnabled(false)
        call AttachSoundToUnit(gg_snd_SentryOnline, udg_DeltaLeader)
        call SetSoundVolume(gg_snd_SentryOnline, 127)
        call StartSound(gg_snd_SentryOnline)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_COMBAT,25.0)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_SPELLS,25.0)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_FIRE,25.0)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_AMBIENTSOUNDS,25.0)
        call MultiboardSetTitleText( udg_SquadStatus, "EM Sphere Engaged." )
        loop
            exitwhen i>5
            call PolledWait(2.0-(0.2*i))
            call StartSound(gg_snd_EMSphere)
            set i=i+1
        endloop
        call MultiboardSetTitleText( udg_SquadStatus, "Electromagnetic Charge Incoming. Shutting Down Non-Vital Systems.." )
        call SetNVGEnabled(false)
        call SetNoise(4.5)
        set udg_Lighting = true
        call StartSound(gg_snd_EMSphereEngagement)
        call PolledWait(4.)
        call SetNoise(8.5)
        call MultiboardSetTitleText( udg_SquadStatus, "Secondary Systems Offline" )
        call PolledWait(1.)
        call CinematicFilterGenericBJ(0.4,BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp",0.0,0.0,0.0,100.0,100.0,100.0,100.0,5.0)
        call PolledWait(1.)
        call CinematicFilterGenericBJ( 2.0, BLEND_MODE_MODULATE_2X, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.0, 100, 100.0, 5, 0, 0, 0, 100.0 )
        set g = GetUnitsInRectMatching(bj_mapInitialPlayableArea,Condition(function SelectEnemyUnits))
        call StartSound(gg_snd_EMSphereBlast)
        call SetNoise(9.5)
        call KillUnit(udg_DeltaLeader)
        call ForGroup(g,function EMSphereDamage)
        call ShiftMoveSpeed(udg_Boss,-100.0)
        set u = CreateUnit(Player(9),'o003',2250.0,4100.0,0.0)
        call UnitAddAbility(u,'A07Z')
        call UnitApplyTimedLife(u,'Bhwd',10.0)
        call IssueImmediateOrder(u,"thunderclap")
        call TriggerSleepAction(0.)
        set u = CreateUnit(Player(13),'o003',2250.0,4100.0,0.0)
        call UnitAddAbility(u,'A07Z')
        call UnitApplyTimedLife(u,'Bhwd',10.0)
        call IssueImmediateOrder(u,"thunderclap")
        call DestroyGroup(g)
        set g = null
        call PolledWait(2.)
        call MultiboardSetTitleText( udg_SquadStatus, "Rebooting Secondary Systems.." )
        call StartSound(gg_snd_EMSphereShockwave)
        call IntermissionRestore()
        call PolledWait(3.)
        set udg_Lighting = false
        call SetNVGEnabled(true)
        call MultiboardSetTitleText( udg_SquadStatus, "Authenticating.." )
        call PolledWait(4.)
        call ClearNoise()
        call GlobalWeather('SNls')
        call ShiftMoveSpeed(udg_Boss,100.0)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_COMBAT,100.0)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_SPELLS,100.0)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_FIRE,100.0)
        call VolumeGroupSetVolume(SOUND_VOLUMEGROUP_AMBIENTSOUNDS,100.0)
        set u = null
        call MultiboardSetTitleText( udg_SquadStatus, "System Restoration Complete.." )
        call PolledWait(4.)
        call MultiboardSetTitleText(udg_SquadStatus,"EM Sphere Released")
    endfunction
    
    //string length 13
    // -release AQ3F
    private function FireEMSphere takes nothing returns nothing
        local player p = GetTriggerPlayer()
        local integer i = GetConvertedPlayerId(p)
        if udg_SectorLockdown then
            call DisableTrigger(GetTriggeringTrigger())
            return
        endif
        call StartSound(gg_snd_ALICEBeep)
        if (SubString(GetEventPlayerChatString(),9,13)==udg_ReleaseCode and StringLength(GetEventPlayerChatString())==13 and udg_DMKills[i]!=1) then
            set udg_EMSphereRelease = udg_EMSphereRelease + 1
            call ALICEText(4.0, "Release Code received." )
            set udg_DMKills[i] = 1
        elseif udg_DMKills[i]==1 then
            call ALICEText(4.0, "Release Code has already been received." )
        else
            call ALICEText(4.0, "Invalid Release Code." )
        endif
        
        if udg_EMSphereRelease>=udg_EMSphereAuthorization and GetWidgetLife(udg_DeltaLeader)>0.405 then
            call DisableTrigger(GetTriggeringTrigger())
            call DestroyTrigger(EMAutoChargeTrigger)
            call ALICE2Text(10.0, "|cff1e90ffManual release override. EM Sphere Initializing..|r" )
            call EMSphereRelease.execute()
        endif
    endfunction
    
    private function EMSphereCycle takes nothing returns nothing
        local group g = CreateGroup()
        local unit u
        call GroupEnumUnitsOfType(g,UnitId2String('z003'),null)
        set u = FirstOfGroup(g)
        if u!=null then
            call ForGroup(g,function EngineerOrders)
            if GetRandomInt(0,2)==1 then
                call GankUnit(u,Player(13),'n00K',1+udg_Spawn,600,1200)
            endif
            set u = null
        endif
        call DestroyGroup(g)
        set g = CreateGroup()
        call GroupEnumUnitsOfType(g,UnitId2String('z005'),null)
        call ForGroup(g,function PatrolToTown)
        call DestroyGroup(g)
        set g = null
        if EMSphereReleased then
            return
        endif
        if udg_SectorLockdown==false and udg_DMDeaths[9]!=1 and udg_EMSphere<250 then
            set udg_EMSphere = udg_EMSphere + udg_EngineersOnSite
            call MultiboardSetTitleText( udg_SquadStatus, "EM Sphere Strength : " + I2S(udg_EMSphere) )
        else
            return
        endif
        if udg_EMSphere>=250 then
            set udg_EMSphere = 250
            if udg_DMDeaths[9]!=1 and udg_ConvoyProgress==1 then
                set udg_DMDeaths[9]=1
                call DisableTrigger(EngineerArriveTrigger)
                call DisableTrigger(EngineerDeployTrigger)
                call ALICEText(10.0, "|cfff3ad00EM Sphere Fully Charged. Ready For Release.|r" )
                call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 10.0, " " )
                call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 10.0, " " )
                call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 10.0, " " )
                call MultiboardSetTitleText( udg_SquadStatus, "EM Sphere Strength : Maximum" )
                call SetUnitScale(udg_DeltaLeader,1.60,1.60,1.60)
                call EMSphereRelease()
            endif
        elseif udg_EMSphere>=200 then
            if udg_DMDeaths[8]!=1 then
                set udg_DMDeaths[8]=1
                call SetUnitScale(udg_DeltaLeader,7.0,7.0,7.0)
                call GeneralText(10.0, "|cffcd950cCombat Engineer|r : The electromagnetic sphere will be fully charged soon. Your combat suits will absorb most of the shock, but it's still going to hurt." )
            endif
        elseif udg_EMSphere>175 then
            if udg_DMDeaths[7]!=1 then
                set udg_DMDeaths[7]=1
                call SetUnitScale(udg_DeltaLeader,6.0,6.0,6.0)
            endif
        elseif udg_EMSphere>150 then
            if udg_DMDeaths[6]!=1 then
                set udg_DMDeaths[6]=1
                call RemoveUnit(udg_DeltaLeader)
                set udg_DeltaLeader = CreateUnit(Player(11),'o006',GetUnitX(udg_Residence41),GetUnitY(udg_Residence41),0.0)
            endif
        elseif udg_EMSphere>100 then
            if udg_DMDeaths[5]!=1 then
                set udg_DMDeaths[5]=1
                call SetUnitScale(udg_DeltaLeader,5.0,5.0,5.0)
            endif
        elseif udg_EMSphere>75 then
            if udg_DMDeaths[4]!=1 then
                set udg_DMDeaths[4]=1
                call SetUnitScale(udg_DeltaLeader,4.0,4.0,4.0)
            endif
        elseif udg_EMSphere>50 then
            if udg_DMDeaths[3]!=1 then
                set udg_DMDeaths[3]=1
                call SetUnitScale(udg_DeltaLeader,3.0,3.0,3.0)
            endif
        elseif udg_EMSphere>25 then
            if udg_DMDeaths[2]!=1 then
                set udg_DMDeaths[2]=1
                call SetUnitScale(udg_DeltaLeader,2.0,2.0,2.0)
                call GeneralText(10.0, "|cffcd950cCombat Engineer|r : We're starting work on the EM sphere now.." )
            endif
        elseif udg_EMSphere>2 then
            if udg_DMDeaths[1]!=1 then
                set udg_DMDeaths[1]=1
                set udg_DeltaLeader = CreateUnit(Player(11),'o005',GetUnitX(udg_Residence41),GetUnitY(udg_Residence41),0.0)
            endif
        endif
        if GetRandomInt(1,100)==1 then
            set udg_soundpath = "Sound\\Interface\\GlueScreenMeteorLaunch3.wav"
            call PlaySoundPath.execute()
        endif
    endfunction


    private function SelectSecurityTeam takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit())=='z005'
    endfunction

    private function EngineerAtSiteConditions takes nothing returns boolean
        return GetUnitTypeId(GetTriggerUnit())=='z003'
    endfunction

    private function EngineerAtSite takes nothing returns nothing
        local location l = GetUnitLoc(GetTriggerUnit())
        local group g = AMGetUnitsInRange(600, l, Condition(function SelectSecurityTeam))
		local unit u = null
		
		call RemoveUnit(GetTriggerUnit())
        call StartSound(gg_snd_Loading)
        set udg_EngineersOnSite = udg_EngineersOnSite + 1
        call MBSet( udg_SquadStatus,1,1, "Engineers on-site : " + I2S(udg_EngineersOnSite))
		
		set u = FirstOfGroup(g)
		if u != null then
			call IssuePointOrder(u,"patrol",GetRectCenterX(gg_rct_Residence41),GetRectCenterY(gg_rct_Residence41))
		endif

        call DestroyGroup(g)
        call RemoveLocation(l)
        set l = null
        set g = null
        set u = null
    endfunction

    private function EngineerDeployment takes nothing returns nothing
        local group g = CreateGroup()
        local unit u
        local integer s = GetRandomInt(2,4)
        local real x = GetRandomReal(GetRectMinX(udg_UndeadRandomSpawn[s]),GetRectMaxX(udg_UndeadRandomSpawn[s]))
        local real y = GetRandomReal(GetRectMinY(udg_UndeadRandomSpawn[s]),GetRectMaxY(udg_UndeadRandomSpawn[s]))
        if udg_Players<=0 or udg_SectorClear or EMSphereReleased then
            call DisableTrigger(GetTriggeringTrigger())
        endif
        set u = CreateUnit(Player(9),'z003',x,y,0.0) //Combat Engineer
        call RemoveGuardPosition(u)
        if udg_SquadXP<50000 then
            call UnitAddItemById(u,'phea') //Fibrin
            call UnitAddItemById(u,'I001') //Composite
        endif
        call SetLoadState(I2S(GetHandleId(u)),1)
        call TriggerSleepAction(0.)
        set x = x+GetRandomReal(-50.0,50.0)
        set y = y+GetRandomReal(-50.0,50.0)
        set u = CreateUnit(Player(9),'z003',x,y,0.0) //Combat Engineer
        call RemoveGuardPosition(u)
        if udg_SquadXP<50000 then
            call UnitAddItemById(u,'I001') //Composite
        endif
        call SetLoadState(I2S(GetHandleId(u)),1)
        if GetPlayerState(Player(9),PLAYER_STATE_RESOURCE_FOOD_USED)<30 then
            set x = x+GetRandomReal(-50.0,50.0)
            set y = y+GetRandomReal(-50.0,50.0)
            set u = CreateUnit(Player(9),'z005',x,y,0.0) //Delta Operator
            call RemoveGuardPosition(u)
            call SetLoadState(I2S(GetHandleId(u)),1)
            if udg_SquadXP<55000 then
                call UnitAddItemById(u,'phea') //Fibrin
            endif
            call UnitAddItemById(u,'I001') //Composite
            call SetUnitUserData(u,69) //Smart Grenades
            call TriggerSleepAction(0.)
            set x = x+GetRandomReal(-50.0,50.0)
            set y = y+GetRandomReal(-50.0,50.0)
            set u = CreateUnit(Player(9),'z005',x,y,0.0) //Delta Operator
            call RemoveGuardPosition(u)
            call SetLoadState(I2S(GetHandleId(u)),1)
            if udg_SquadXP<55000 then
                call UnitAddItemById(u,'I004') //Medkit
                call UnitAddItemById(u,'I00O') //TX-1
            endif
            call UnitAddItemById(u,'I001') //Composite
            call SetUnitUserData(u,69)
            call GroupEnumUnitsOfType(g,UnitId2String('z003'),null)
            call ForGroup(g,function EngineerOrders)
            call DestroyGroup(g)
            set g = CreateGroup()
            call GroupEnumUnitsOfType(g,UnitId2String('z005'),null)
            call ForGroup(g,function PatrolToTown)
            call DestroyGroup(g)
        endif
        if udg_SquadXP>40000 then
            call PolledWait(GetRandomReal(20.0,50.0))
            if GetWidgetLife(u)>0.405 then
                call GankUnit(u,Player(13),'n00N',2,700,1400)
            endif
        endif
        set u = null
        set g = null
    endfunction

    private function UndeadClimax takes nothing returns nothing
        local integer i
        if (GetPlayerState(Player(13),PLAYER_STATE_RESOURCE_FOOD_USED)>70 or GetPlayerState(Player(14),PLAYER_STATE_RESOURCE_FOOD_USED)>70) then
            return
        endif
        call GankMarine(Player(13),'n00N',udg_Spawn,1500,2500)
        call GankMarine(Player(14),'u005',2*udg_Spawn,1500,2500)
        call RandomSpawn('n001',1,udg_Spawn) //Immortal #2
        call RandomSpawn('u00C',2,udg_Spawn) //Gargolye #3
        if udg_SquadXP>55000 then
            call RandomSpawn('u00O',2,udg_Spawn) //Leviathan
        elseif udg_SquadXP>20000 then
            call RandomSpawn('u00O',1,udg_Spawn) //Leviathan
        endif
        call GankMarine(Player(13),'n00N',udg_Spawn,1500,2500)
        if GetRandomInt(0,2)==1 then
            call RandomSpawn('z002',2,udg_Players) //Slasher
        else
            call RandomSpawn('n002',2,udg_Players) //Devourer
        endif
        if udg_DMKills[1]==1 then
            return
        endif
        if GetRandomInt(0,1)==1 then
            set i = 14
        else
            set i = 13
        endif
        set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        if GetRandomInt(0,3)==1 then
            set udg_Boss = CreateUnitAtLoc(Player(i),'U009',udg_myloc,0) //Atlas
        elseif GetRandomInt(0,3)==1 then
            set udg_Boss = CreateUnitAtLoc(Player(i),'U00B',udg_myloc,0) //Loki #2
        elseif GetRandomInt(0,6)==1 then
            set udg_Boss = CreateUnitAtLoc(Player(i),'N00F',udg_myloc,0) //Lyganesh #2
        elseif GetRandomInt(0,6)==1 then
            set udg_Boss = CreateUnitAtLoc(Player(i),'U006',udg_myloc,0) //Thanatos #2
        elseif GetRandomInt(0,2)==1 then
            set udg_Boss = CreateUnitAtLoc(Player(i),'U00K',udg_myloc,0) //Minos
        elseif GetRandomInt(0,2)==1 then
            set udg_Boss = CreateUnitAtLoc(Player(i),'U007',udg_myloc,0) //Eris
        endif
        call SuspendHeroXP(udg_Boss,true)
        call RemoveLocation(udg_myloc)
        
        call SpawnShredder()
    endfunction


    private function MBIcon3 takes multiboard mb, integer col, integer row, string iconFileName returns nothing
        local multiboarditem mbitem = MultiboardGetItem(mb, row - 1, col - 1)
        call MultiboardSetItemIcon(mbitem, iconFileName)
        call MultiboardReleaseItem(mbitem)
        set mbitem = null
    endfunction

    private function ShivaLockdown takes nothing returns nothing
        local integer i = 1
        local unit u
        local location l
        local real x
        local real y
        local real x2
        local real y2
        local rect r
        local boolean visual = false

        if(i == 1) then
             return 
        endif

        if udg_ConvoyProgress==1 then
            loop
                exitwhen i > udg_InitialPlayers
                if IsUnitVisible(udg_Boss,ConvertedPlayer(udg_Sorted[i])) then
                    set visual = true
                endif
                set i = i + 1
            endloop
            if GetWidgetLife(udg_Boss)>0.405 and visual then
                set x2 = GetUnitX(udg_Boss)
                set y2 = GetUnitY(udg_Boss)
                set x = GetRandomReal(x2-1800.0,x2+1800.0)
                set y = GetRandomReal(y2-1800.0,y2+1800.0)
            else
                set x = GetRandomReal(-6000.0,10000.0)
                set y = GetRandomReal(-5000.0,14000.0)
            endif
        else
            set x = GetRandomReal(-6000.0,10000.0)
            set y = GetRandomReal(-5000.0,14000.0)
        endif
        set l = Location(x,y)
        set r = Rect( x - 1000, y - 1000, x + 1000, y + 1000 )
        set i = 1
        loop
            exitwhen i>udg_InitialPlayers
            call PingMinimapEx(x,y,10.0,255,0,0,false)
            set u = CreateUnit(ConvertedPlayer(udg_Sorted[i]),'e002',x,y,0.0)
            call UnitApplyTimedLife(u,'Bhwd',20.0)
            call TriggerSleepAction(0.)
            set i=i+1
        endloop
        call SetCameraQuickPosition(x,y)
        call PolledWait(3.)
        set u = CreateUnit(Player(11),'e00K',x,y,0.0) //Mushroom Cloud
        call UnitApplyTimedLife(u,'Bhwd',7.0)
        call PolledWait(0.5)
        call WhiteFlash.execute()
        //set u = CreateUnit(Player(11),'e004',x,y,0.0) //Shiva Radiation
        //call UnitApplyTimedLife(u, 'Bhwd', 240.0)
        //call TerrainDeformationCraterBJ(2.0, true, l, 900.0, 35.0)
        //call MicroWeather('WOlw',l,900.0,60.0)
        call SetTerrainType(x, y, 'Xdrt',  -1, 11, 0)
        call EnumItemsInRect(r,null,function killitem)
        set udg_myinteger = 10
        call EnumDestructablesInRect(r,null,function killtree)
        call UnitDamagePoint( udg_Residence41, 0, 1300.0, x, y, 75000.0, true, false, ATTACK_TYPE_SIEGE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS )
        call RemoveLocation(l)
        call StartSound(gg_snd_Shiva)
        set i = 1
        loop
            exitwhen i>15
            set l = GetRandomLocInRect(r)
            set u = CreateUnit(Player(11),'o002',GetLocationX(l),GetLocationY(l),0.0)
            call UnitApplyTimedLife(u, 'Bhwd', 240.0)
            call RemoveLocation(l)
            if GetRandomInt(0,1)==1 then
                call TriggerSleepAction(0.)
            endif
            set i=i+1
        endloop
        call SetNoise(8.5)
        call PolledWait(2.75)
        call IntermissionRestore.execute()
        call ClearNoise()
        call RemoveRect(r)
        set u = null
        set r = null
        set l = null
        if udg_SectorClear then
            call DisableTrigger(GetTriggeringTrigger())
        endif
    endfunction

    private function Residence41Destroyed takes nothing returns nothing
        local unit u
        local integer i = 1
        local trigger t
        call DisableTrigger(GetTriggeringTrigger())
        call DisableTrigger(EngineerArriveTrigger)
        call DisableTrigger(EngineerDeployTrigger)
        if udg_SectorClear then
            return
        endif
        set udg_AITarget = null
        set udg_SectorLockdown = true
        if GetWidgetLife(udg_DeltaLeader)>0.405 then
            call KillUnit(udg_DeltaLeader)
        endif
        set udg_Residence41 = CreateUnit(Player(11),'e00F',0.0,0.0,0.0)
        call ALICE2Text(10.0, "Residence 41 destroyed. Perimeter security compromised. Immediate withdrawal required of all ground forces." )
        call PolledWait(15.)
        call ALICE2Text(30.0, "Sector Lockdown. Initializing sanitation procedures." )
        call PolledWait(10.)
        call StartSound(gg_snd_WillyPeter)
        set u = CreateUnit(Player(11),'e00L',-936.0,-75.5,0.0)
        call UnitApplyTimedLife(u,'Bhwd',60.0)
        call TriggerSleepAction(0.)
        set u = CreateUnit(Player(11),'e00L',-461.0,-75.5,0.0)
        call UnitApplyTimedLife(u,'Bhwd',60.0)
        set t = CreateTrigger()
        call TriggerRegisterTimerEvent(t,14.0,true)
        call TriggerAddAction(t,function ShivaLockdown)
        set t = null
    endfunction


    private function M242AmmunitionFeedConditions takes nothing returns boolean
        return GetUnitTypeId(GetTriggerUnit())=='h00K'
    endfunction

    private function M242AmmunitionFeed takes nothing returns nothing
        local item i = GetManipulatedItem()
        local unit u = GetTriggerUnit()
        local integer id = GetItemTypeId(i)
        if id=='I006' or id=='shas' then
            call PauseUnit(u,false)
            call MachineGunLink(u)
            call SetUnitState(u,UNIT_STATE_MANA,GetUnitState(u,UNIT_STATE_MANA)+(50*I2R(GetItemCharges(i))))
            call AddFadingTextTag("+"+I2S(50*GetItemCharges(i)),GetUnitX(u),GetUnitY(u),255,220,0,200)
            call RemoveItem(i)
        else
            call UnitRemoveItem(u,i)
        endif
        set i = null
        set u = null
    endfunction

    private function M242AmmunitionSystemConditions takes nothing returns boolean
        return  GetUnitTypeId(GetAttacker())=='h00K'
    endfunction

    private function M242AmmunitionSystem takes nothing returns nothing
        local unit u = GetAttacker()
        local real rounds = GetUnitState(u,UNIT_STATE_MANA)
        if rounds<0.5 then
            call IssueImmediateOrder(u,"stop")
        else
            if rounds-1.0<0 then
                set rounds=0
            else
                set rounds=rounds-1.0
            endif
                call SetUnitState(u,UNIT_STATE_MANA,rounds)
        endif
        set u = null
    endfunction
        
    private function Residence41DefenseMechanism takes nothing returns nothing
        local trigger t = null
        if GetWidgetLife(GetTriggerUnit())<5000.0 then
            call DisableTrigger(GetTriggeringTrigger())
            call ALICE2Text(10.0, "Emergency Defense Mechanism Activated." )
            call CreateUnit(Player(11),'h00K',-936.0,-75.5,0.0)
            call TriggerSleepAction(0.)
            call CreateUnit(Player(11),'h00K',-461.0,-75.5,0.0)
            
            // if there was no delta wave, we need to create the turret triggers here ..zzz
            set t= CreateTrigger()
            call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
            call TriggerAddCondition( t, Condition( function M242AmmunitionFeedConditions ) )
            call TriggerAddAction( t, function M242AmmunitionFeed )
                
            set t = CreateTrigger()
            call TriggerRegisterPlayerUnitEvent(t, Player(13), EVENT_PLAYER_UNIT_ATTACKED, null)
            call TriggerRegisterPlayerUnitEvent(t, Player(14), EVENT_PLAYER_UNIT_ATTACKED, null)
            call TriggerAddCondition( t, Condition( function M242AmmunitionSystemConditions ) )
            call TriggerAddAction( t, function M242AmmunitionSystem )
        endif
    endfunction


    private function EnableMOSSelection takes nothing returns nothing
        local integer i = 1
        local integer i3
        if udg_DMDeliveryTime[101]<1337.0 then
            set udg_DMDeliveryTime[101] = 1337.0
            //call EnableTrigger(gg_trg_ShowStats)
            call PolledWait(5.)
            set i3=1
            loop
                exitwhen i3>udg_InitialPlayers
                
                set i3=i3+1
            endloop
        endif
    endfunction

    private function FinalTransmission takes nothing returns nothing
        local integer i = 1
        call EnableMOSSelection.execute()
        if udg_SectorLockdown then
            call EndSequenceC.execute()
        elseif GetRandomInt(0,1)==1 then
            call EndSequenceB.execute()
        else
            set udg_bunny_boss = CreateUnit(Player(14),'U00Q',GetRandomReal(-4000.0,8000.0), GetRandomReal(-4000.0,8000.0),0.0)
            call SuspendHeroXP(udg_bunny_boss,true)
            set udg_soundpath = "Units\\Critters\\EasterRabbit\\RabbitWhat1.wav"
            call PlaySoundPath.execute()
            call DisableAilmentChecks()
            call PolledWait(3.)
            set i = GetRandomInt(1,udg_Players)
            call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : Fluffy?!" )
            loop
                exitwhen GetWidgetLife(udg_bunny_boss)<0.405 or udg_Players<1
				call AIBunny()
                call PolledWait(5.)
            endloop
            if GetWidgetLife(udg_bunny_boss)>0.405 then
                return
            endif
            call PolledWait(2.)
            call EndSequenceA.execute()
        endif
    endfunction

    private function MedevacHeloArea takes nothing returns nothing
        local location l = Location(GetRectCenterX(gg_rct_LZ_Two),GetRectCenterY(gg_rct_LZ_Two))
        local group g = AMGetUnitsInRange(325,l,Condition(function SelectGround))
        local unit u
        local item n
        local integer i=1
        loop
            set u = FirstOfGroup(g)
            exitwhen u==null
            set n = GetUnitItem(u,'I018')
            if n!=null then
                call RemoveItem(n)
                call ALICE2Text(10.0, "Kilo evacuated. |cff1e90ff10 XP|r awarded to all Marines." )
                set i=1
                loop
                    exitwhen i>udg_InitialPlayers
                    if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                        set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + 10
                    endif
                    set i=i+1
                endloop
            endif
            call GroupRemoveUnit(g,u)
        endloop
        call DestroyGroup(g)
        set g = null
        call RemoveLocation(l)
        set l = null
        set n = null
    endfunction

    private function MedevacHelo takes nothing returns nothing
        local trigger t = CreateTrigger()
        local real handicap = 0.0
        local integer i = 1
        local integer id = 0
        local real x = GetRectCenterX(udg_LandingZones[2])
        local real y = GetRectCenterY(udg_LandingZones[2])
        local location l
        local real angle
        local boolean present
        local unit u
        local real theta = GetRandomReal(0.0,6.28)
        local real ux = Clamp(x+3000.0*Cos(theta),GetRectMinX(bj_mapInitialPlayableArea),GetRectMaxX(bj_mapInitialPlayableArea))
        local real uy = Clamp(y+3000.0*Sin(theta),GetRectMinY(bj_mapInitialPlayableArea),GetRectMaxY(bj_mapInitialPlayableArea))
        local unit blackhawk
        set l = Location(x,y)
        set udg_LZPoint = Location(x,y)
        set blackhawk = CreateUnit(Player(11),'h009',ux,uy,theta+3.14)
        call UnitApplyTimedLife(blackhawk,'Bhwd',60.0)
        call SetUnitScalePercent(blackhawk,50.0,50.0,50.0)
        call RemoveGuardPosition(blackhawk)
        call TriggerSleepAction(0.)
        call IssuePointOrder(blackhawk,"move",x,y)
        call StartSound(gg_snd_BlackHawkRotor)
        call PolledWait(5.5)
        call SetUnitFlyHeight(blackhawk,15.0,130.0)
        call SmoothUnitResize(blackhawk,0.6,1.2,4)
        call SetLandingAreaWindEnabled(true)
        call PolledWait(3.)
        call SetUnitTimeScalePercent(blackhawk,65.0)
        call BlackHawkWashOff.execute()
        call HeloShock(blackhawk)
        call AttachSoundToUnit(gg_snd_BlackHawkLand,blackhawk)
        call SetSoundVolume(gg_snd_BlackHawkLand,127)
        call StartSound(gg_snd_BlackHawkLand)
        call PolledWait(2.5)
        call KiloEvac(blackhawk)
        call TriggerRegisterEnterRectSimple(t,gg_rct_LZ_Two)
        call TriggerRegisterLeaveRectSimple(t,gg_rct_LZ_Two)
        call TriggerAddAction(t,function MedevacHeloArea)
        set t=null
        set blackhawk=null
    endfunction

    private function PrometheusDeath takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local integer i = 1
        local integer xp = 150
        local integer spawnfactor = 3
        if udg_SquadXP>40000 then
            set spawnfactor=1
        endif
        if GetRandomInt(1,spawnfactor)==1 then
            call AttachSoundToUnit(gg_snd_ParasiteSpawn, u)
            call SetSoundVolume(gg_snd_ParasiteSpawn, 127)
            call StartSound(gg_snd_ParasiteSpawn)
            loop
                exitwhen i>5
                call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Undead\\UndeadBlood\\UndeadBloodNecromancer.mdl",x,y ))
                call CreateUnit(Player(13),'n009',x,y,0.0)
                call TriggerSleepAction(0.)
                call CreateUnit(Player(13),'n009',x+5.0,y+5.0,0.0)
                call TriggerSleepAction(0.)
                call CreateUnit(Player(13),'ucs1',x+GetRandomReal(-20.0,20.0),y+GetRandomReal(-20.0,20.0),0.0) //Unknown Entity
                set i=i+1
            endloop
            call StartSound(gg_snd_ParasiteSpawn)
        endif
        set i=1
        set u = null
          
        call DisableTrigger(EngineerArriveTrigger)
        call DisableTrigger(FinalUndeadSpawnTrigger)
        call DisableTrigger(EngineerDeployTrigger)
        call DisableTrigger(FinalBossKillListenerTrigger)
        
        call SetAINeutralVictimEnabled(false)

       // call EnableTrigger(gg_trg_ShowStats)
        set udg_TheCloud = true
        set udg_CloudFactor = 7777
        set udg_SectorClear = true
		call SetMOSEnabled(true)
		
        call MultiboardSetTitleText( udg_SquadStatus, "Objectives Complete." )
        call ALICEText(5.0, "Prometheus Eliminated. No major threats remain in Sector E." )
        call PolledWait(10.)
        if (udg_Mode==1 or udg_Mode==4) and udg_Players>0 then
            if udg_SectorLockdown then
                set xp = 50
            endif
            if udg_Difficulty==5 then
                set xp = xp + 300
            endif
            call ALICE2Text(10.0, "Operation Silent Hill Complete. |cff1e90ff" + I2S(xp) + " XP|r awarded to all Marines." )
            loop
                exitwhen i>udg_InitialPlayers
                if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                    set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + xp
                endif
                set i=i+1
            endloop
        endif
        set udg_Lighting = true
        call SetNoise(8.5)
        call StartSound(gg_snd_RPGMissile)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, 0.5, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.0, 100.0, 100.0, 5.0 )
        call PolledWait(1.)
        call SetNoise(9.5)
        call StartSound(gg_snd_Shiva)
        call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 2.0, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.0, 100.0, 100.0, 5.0 )
        set udg_mygroup = GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function SelectEnemyUnits))
        set udg_EMSphere = 250
        set udg_Lighting = false
        call ForGroup( udg_mygroup, function EMSphereDamage )
        call DestroyGroup(udg_mygroup)
        call MedevacHelo.execute()
        call PolledWait(5.)
        call ClearNoise()
        call PolledWait(15.)
        call GeneralText(5.0, "|cffcd950cCaptain Roth|r : We fuckin' did it." )
        call PolledWait(5.)
        if GetRandomInt(1,3)==1 then
            call GeneralText(2.5, "|cffcd950cMarine|r : I need some R&R." )
        else
            call GeneralText(2.5, "|cffcd950cMarine|r : Is it over?" )
        endif
        call PolledWait(8.)
        set i=1
        if udg_Mode==1 and udg_Players>5 and udg_InitialPlayers==udg_Players then
            if udg_Difficulty==5 then
                set xp = 500
            else
                set xp = 250
            endif
            call ALICE2Text(10.0, "Zero casualties. |cff1e90ff" + I2S(xp) + " XP|r awarded to all Marines." )
            loop
                exitwhen i>udg_InitialPlayers
                if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                    set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + xp
                endif
                set i=i+1
            endloop
        endif
        call PolledWait(30.)
        call FinalTransmission.execute()
    endfunction

    private function Wave18a takes nothing returns nothing
        local location l
        local real x
        local real y
        local real dx
        local real dy
        local integer i = 1
        local integer codeset
        local real handicap = 10.0
        local group g = CreateGroup()
        local trigger t = CreateTrigger()
        local timer BossArrival = CreateTimer()
        local timerdialog BossArrivalBoard
        set udg_ConvoyProgress = 0
        set bj_groupEnumTypeId = 'h001'
        call GroupEnumUnitsOfPlayer(g , Player(11), filterGetUnitsOfTypeIdAll)
        set bj_groupEnumTypeId = 'hgyr'
        call GroupEnumUnitsOfPlayer(g , Player(11), filterGetUnitsOfTypeIdAll)
        call ForGroup( g, function RemoveUnitAll )
        call DestroyGroup(g)
        set g = null
        set i = 1
        loop
            exitwhen i>12
            set udg_DMDeaths[i] = 0
            set i=i+1
        endloop
        set udg_CurrentWave = 18
        call SetPlayerName( Player(9), "1st SFOD-D" )
        call GenericActions.execute()
        call ItemSpawnN('I00H',2) //XML-9C
        if udg_Difficulty>=4.0 then
            set handicap = 15.0
        endif
        call SetPlayerHandicapBJ(Player(13), GetPlayerHandicapBJ(Player(13)) + handicap)
        call SetPlayerHandicapBJ(Player(14), GetPlayerHandicapBJ(Player(14)) + handicap)
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], GetPlayersByMapControl(MAP_CONTROL_USER), bj_ALLIANCE_ALLIED_VISION )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[9], bj_ALLIANCE_UNALLIED ) //Failsafe
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[9], bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[13], bj_FORCE_PLAYER[11], bj_ALLIANCE_UNALLIED )
        call SetForceAllianceStateBJ(bj_FORCE_PLAYER[11], bj_FORCE_PLAYER[13], bj_ALLIANCE_UNALLIED )
        call GeneralText(10.0, "|cffcd950cBattalion|r : This is Iron Hand. Be advised, Prometheus has been spotted and is headed towards your sector. We've been unable to stop it." )
        call PolledWait(10.)
        call SetSmartGrenadesEnabled(true)
        
    
        if EngineerDeployTrigger == null then
            set EngineerDeployTrigger = CreateTrigger()
            call TriggerRegisterTimerEvent(EngineerDeployTrigger, 45.0*udg_Pace,true)
            call TriggerAddAction(EngineerDeployTrigger,function EngineerDeployment)
        endif
        
        if EngineerArriveTrigger == null then
			set EngineerArriveTrigger = CreateTrigger()
			call TriggerRegisterEnterRectSimple( EngineerArriveTrigger, gg_rct_Residence41 )
            call TriggerAddCondition( EngineerArriveTrigger, Condition( function EngineerAtSiteConditions ) )
            call TriggerAddAction(EngineerArriveTrigger,function EngineerAtSite)
        endif
        
        if FinalUndeadSpawnTrigger == null then
            set FinalUndeadSpawnTrigger = CreateTrigger()
            call TriggerRegisterTimerEvent(FinalUndeadSpawnTrigger, 60.0*udg_Pace,true)
            call TriggerAddAction(FinalUndeadSpawnTrigger,function UndeadClimax)
        endif
      
        if EMAutoChargeTrigger == null then
            set EMAutoChargeTrigger = CreateTrigger()
            call TriggerRegisterTimerEvent(EMAutoChargeTrigger, 10.0*udg_Pace,true)
            call TriggerAddAction(EMAutoChargeTrigger,function EMSphereCycle)
        endif
        
		set udg_EngineersOnSite = 0
        call EnableTrigger(EngineerDeployTrigger)
        call EnableTrigger(EngineerArriveTrigger)
        call EnableTrigger(FinalUndeadSpawnTrigger)
        call EnableTrigger(EMAutoChargeTrigger)

        
        call GeneralText(10.0, "|cffcd950cBattalion|r : Combat Engineers are coming to set up an EM Sphere. D-boys will be escorting them to the town. Secure to Residence 41 and keep it intact. Out." )
        call MultiboardSetTitleText( udg_SquadStatus, "EM Sphere Strength : " + I2S(udg_EMSphere) )
        call MBSet( udg_SquadStatus, 1, 1, "Engineers on-site : " + I2S(udg_EngineersOnSite) )
        call QuestSetDescription(udg_CurrentOrders, "Provide auxiliary support to Delta Operators. The Engineer teams will periodically appear at the edge of your sector and make their way towards Ravenholm. Combat Engineers must reach Residence 41 and set up the EM Sphere. |n|nThe EM Sphere is a single charge weapon that will deal significant damage based on its state of completion. Residence 41 must not be destroyed." )
        call MBIcon3( udg_SquadStatus, 1, 1, "ReplaceableTextures\\CommandButtons\\BTN_Unit_Engineer.blp" )
        call MissionUpdate.execute()
        if udg_SquadXP>20000 then
            call RandomSpawn('n016',3,udg_Spawn) //Invi Worm
        else
            call SpawnRectRandom(gg_rct_SpawnEastCave,Player(14),'n004',2+GetRandomInt(1,udg_Spawn))
        endif
        call SpawnRectRandom(gg_rct_SpawnEastBottom,Player(13),'n003',GetRandomInt(1,udg_Spawn))
        call SpawnRectRandom(gg_rct_SpawnTownWestCave,Player(13),'n00N',2*udg_Spawn)
        call PolledWait(5.)
        set udg_soundpath = "Sound\\Interface\\GlueScreenMeteorLaunch3.wav"
        call PlaySoundPath.execute()
        call PolledWait(5.)
        call MultiboardSetTitleText( udg_SquadStatus, "Capt. Roth : The Engineers are on their way." )
        call ALICE2Text(5.0, "|cff8b864eNew Objective|r : Clear the way for Combat Engineers. Residence 41 must not be destroyed." )
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(14),'n004',2+GetRandomInt(1,udg_Spawn))
        call SpawnRectRandom(gg_rct_SpawnSouthWaterfall,Player(13),'n003',GetRandomInt(1,udg_Spawn))
        call SpawnRectRandom(gg_rct_SpawnWestTop,Player(14),'n004',2+GetRandomInt(1,udg_Spawn))
        call PolledWait(20.0*udg_Pace)
        call GankMarine(Player(14),'u005',2*udg_Spawn,1200,1800)
        call GankMarine(Player(14),'u005',2*udg_Spawn,1200,1800)
        call GeneralText(10.0, "|cffcd950cCaptain Roth|r : We'll give all the support we can afford. I've lost most of my men." )
        call PolledWait(4.)
        set i = GetRandomInt(1,udg_Players)
        call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : Watch your six!" )
        call PolledWait(10.)
        call GeneralText(10.0, "|cffcd950cMarine|r : The more Engineers we bring in safely, the quicker this will be over." )
        set udg_AITarget = udg_Residence41
		
        call UnitRemoveAbility(udg_Residence41,'Avul')
        call TriggerRegisterUnitEvent( t, udg_Residence41, EVENT_UNIT_DEATH )
        call TriggerAddAction( t, function Residence41Destroyed )
        set t = CreateTrigger()
        call TriggerRegisterUnitEvent( t, udg_Residence41, EVENT_UNIT_DAMAGED )
        call TriggerAddAction( t, function Residence41DefenseMechanism )
		
        set t = null
        set i=1
        set udg_EMSphereAuthorization=0
        loop
            exitwhen i>udg_Players
            if GetWidgetLife(udg_Hero[udg_Sorted[i]])>0.405 and udg_Leaver[udg_Sorted[i]]==false then
                set udg_EMSphereAuthorization=udg_EMSphereAuthorization+1
            endif
            set i=i+1
        endloop
        set i = 1
        loop
            exitwhen i>12
            set udg_DMKills[i] = 0
            set i=i+1
        endloop
        set codeset = GetRandomInt(1,6)
        if codeset==1 then
            set udg_ReleaseCode="AQ3F"
        elseif codeset==2 then
            set udg_ReleaseCode="R5ED"
        elseif codeset==3 then
            set udg_ReleaseCode="BO7N"
        elseif codeset==4 then
            set udg_ReleaseCode="9JKZ"
        elseif codeset==5 then
            set udg_ReleaseCode="UYC2"
        else
            set udg_ReleaseCode="HDE4"
        endif
        
        call StartSound(gg_snd_ALICEBeep)
        
        if EMManualReleaseTrigger != null then
            call DestroyTrigger(EMManualReleaseTrigger)
        endif
        set EMManualReleaseTrigger = CreateTrigger()
        call TriggerAddAction(EMManualReleaseTrigger, function FireEMSphere)
        set i=1
        loop
            exitwhen i>udg_Players
            call TriggerRegisterPlayerChatEvent(EMManualReleaseTrigger, ConvertedPlayer(udg_Sorted[i]), "-release", false)
            call DisplayTimedTextToPlayer(ConvertedPlayer(udg_Sorted[i]),0.0,0.0,45.0, "Your release code is " + udg_ReleaseCode + ". Input -release **** to manually release the EM Sphere." )
            set i = i+1
        endloop
        
        call QuestSetDescription(udg_CurrentOrders, "Neutralize Prometheus. The EM Sphere can be manually released when all players enter their release codes (-release " + udg_ReleaseCode + "). The EM Sphere is a single charge weapon that will deal significant damage based on its state of completion. It is our key weapon against Prometheus. Airstrikes are also an effective weapon against Prometheus. Airstrikes must be targeted precisely for maximum results." )
        call MissionUpdate.execute()
        call TimerStart(BossArrival, 240.0, false, null)
        set BossArrivalBoard = CreateTimerDialog(BossArrival)
        call TimerDialogSetTitle(BossArrivalBoard,"ETA.")
        call TimerDialogSetTimeColor(BossArrivalBoard, 242, 0, 0, 255)
        call TimerDialogDisplay(BossArrivalBoard, true)
        call PolledWait(120.0)
        if udg_EMSphere>50 then
            call GeneralText(10.0, "|cffcd950cCaptain Roth|r : We're on track. Let's hope this electromagnetic sphere does the trick." )
        else
            call GeneralText(10.0, "|cffcd950cCaptain Roth|r : Damn it! We got to get those Engineers to the site." )
        endif
        call PolledWait(120.)
        call TimerDialogDisplay(BossArrivalBoard, false)
        call DestroyTimerDialog(BossArrivalBoard)
        call PauseTimer(BossArrival)
        call DestroyTimer(BossArrival)
        set BossArrivalBoard = null
        set BossArrival = null
        set udg_ConvoyProgress = 1
        call MultiboardSetTitleText( udg_SquadStatus, "Neutralize Prometheus." )
        set l = GetRandomLocInRect(bj_mapInitialPlayableArea)
        loop
            set x = GetLocationX(l)
            set y = GetLocationY(l)
            set dx = x-GetUnitX(udg_Residence41)
            set dy = y-GetUnitY(udg_Residence41)
            exitwhen dx*dx+dy*dy>25000000.0 //5000 radius
            call RemoveLocation(l)
            set l = GetRandomLocInRect(bj_mapInitialPlayableArea)
        endloop
        set udg_Boss = CreateUnitAtLoc(Player(13),'U00P',l,0.0) //Prometheus
        call SuspendHeroXP(udg_Boss,true)
        call RemoveLocation(l)
        set l = null
        call PlatoonReinforcements.execute()
        
        
        if FinalBossKillListenerTrigger != null then
            call DestroyTrigger(FinalBossKillListenerTrigger)
        endif
        set FinalBossKillListenerTrigger = CreateTrigger()
        call TriggerAddAction(FinalBossKillListenerTrigger,function PrometheusDeath)
        call TriggerRegisterUnitEvent( FinalBossKillListenerTrigger, udg_Boss, EVENT_UNIT_DEATH )
        
        
        set udg_soundpath = "Units\\Undead\\ObsidianStatue\\ObsidianAvengerReady1.wav"
        call PlaySoundPath.execute()
        call PolledWait(5.)
        call GeneralText(3.0, "|cffcd950cMarine|r : We're not going to survive this!" )
        call PolledWait(3.)
        call GeneralText(3.0, "|cffcd950cMarine #2|r : I think he's right. How are we going to take it down?" )
        call PolledWait(3.)
        call GeneralText(5.0, "|cffcd950cCaptain Roth|r : Come on, you sons of bitches, do you want to live forever?" )
        call PolledWait(2.)
        set udg_soundpath = "Abilities\\Spells\\Human\\MarkOfChaos\\MarkOfChaos.wav"
        call PlaySoundPath.execute()
        call PolledWait(2.)
        call ALICEText(5.0, "|cff8b864eNew Objective|r : Neutralize Prometheus. Residence 41 must remain operational." )
        call StartSound(gg_snd_Battle)
        set i = 1
        loop
            call PolledWait(180.0*udg_Pace)
            exitwhen udg_SectorClear or i>5
            call ShiftMoveSpeed(udg_Boss,50.0)
            set udg_soundpath = "Units\\Undead\\ObsidianStatue\\ObsidianAvengerReady1.wav"
            call PlaySoundPath.execute()
            if i==2 then
                call UnitAddAbility(udg_Boss,'Atru')
            endif
            set i=i+1
        endloop
    endfunction

    private function init takes nothing returns nothing
        call RegisterFunction("Wave18a", function Wave18a)
    endfunction

endlibrary